package regex;
/*
* 预定义字符规则:具有特殊含义的字符
*  .:.可以匹配任意字符
* \d(digit):相当于[0-9]
* \w(word):相当于[a-zA-Z_0-9]
* */
public class RegexDemo04 {
    public static void main(String[] args) {
        //method01();
        //method02();
        method03();
    }

    private static void method03() {
        System.out.println("a".matches("\\w"));//true
        System.out.println("1".matches("\\w"));//true
        System.out.println("%".matches("\\w"));//false
    }

    private static void method02() {
        System.out.println("1".matches("\\d"));//true
        System.out.println("a".matches("\\d"));//false
        System.out.println("19".matches("\\d\\d"));//true
        System.out.println("19".matches("[0-9][0-9]"));//true
    }

    private static void method01() {
        System.out.println("a".matches("."));//true
        System.out.println("1".matches("."));//true
        System.out.println("*".matches("."));//true
        System.out.println("aa".matches("."));//false//匹配字符串长度为1
        System.out.println(".".matches("\\."));//由于.在正则中具有特殊含义,所以需要加/.来进行转义让他失去含义成为普通字符
        //但是在java中只有\t,\n,\r等转义字符,因此需要再加一个\来\失去转义的效果
        //简单理解就是在java中两个\\代表一个\
        System.out.println("a".matches("\\."));//false
    }
}
